import * as Minio from 'minio';

import { Module } from '@nestjs/common';
import { MinioService } from './minio.service';
import { MinioController } from './minio.controller';

export const MINIO_CLIENT = 'MINIO_CLIENT';

const MINIO_CONFIG = {
  endPoint: 'localhost',
  port: 6002,
  useSSL: true,
  // accessKey: '29Rxwp8k2m9NSPm9BKZo',
  // secretKey: 'UwTEKLL8W9425nAOVMQcV5m77OXiVKwR7KTbHdgX',
  accessKey: 'minio',
  secretKey: 'minio@123',

  // accessKey: 'MEMOx5lPEyotV0tE9XIG',
  // secretKey: 'LA8py3FZNNwdgwFy1CmfgtXbDLF2tzu0ENIhbku7'
  // port: 9000,
  // useSSL: false,
  // accessKey: 'IAEg16eWbe5k85yDOrRU',
  // secretKey: 'AOw5U0rIgToOqjiWfYXicghZd3nWwF2ZBOH6k4je',
};

@Module({
  controllers: [MinioController],
  providers: [
    {
      provide: MINIO_CLIENT,
      async useFactory() {
        const client = new Minio.Client({
          endPoint: MINIO_CONFIG.endPoint,
          port: MINIO_CONFIG.port,
          useSSL: MINIO_CONFIG.useSSL,
          accessKey: MINIO_CONFIG.accessKey,
          secretKey: MINIO_CONFIG.secretKey,
        });

        return client;
      },
    },
    MinioService,
  ],
  exports: [MINIO_CLIENT, MinioService],
})
export class MinioModule {}
